from sys import argv

with open(argv[1]) as kk, open(argv[2]) as fa:
    ks = {}
    for i in kk:
        if not i.startswith('U'):
            item = i.split('\t')
            if len(item[2].split(' (')[0].split()) == 1:
                continue
            #lenT = len(item[2].split(' (')[0].split())
            #if item[2].find(' group (') > -1 or item[2].find(' complex (') > -1 or lenT == 1:
            #    continue
            t = item[2].split()[-1].replace(')', '')
            s = item[4].split()
            tsum = 0
            allsum = 0
            if t in ['77643', '1773'] or t in ['120793', '1764', '1767']:
                for n in s:
                    st, kn = n.split(':')
                    if st == 'A':
                        continue
                    if st in ['77643', '1773'] or st in ['120793', '1764', '1767']:
                        tsum += int(kn)
                    allsum += int(kn)
            else:
                for n in s:
                    st, kn = n.split(':')
                    if st == 'A':
                        continue
                    if st == t:
                        tsum += int(kn)
                    allsum += int(kn)
            if tsum / allsum > 0.5:
                ks[f'>{item[1]}\n'] = 0    

    flag = 0
    for i in fa:
        if i.startswith('>'):
            if i in ks:
                flag = 1
                print(i, end='')
            else:
                flag = 0
        else:
            if flag == 1:
                print(i, end='')
